package threadpool;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/8/9 19:11
 */

public class ThreadTest {
    public static void main(String[] args){
        int availProcessors = Runtime.getRuntime().availableProcessors();
        long freeMemory = Runtime.getRuntime().freeMemory();
        System.out.println("avail processors count: " + availProcessors+"   "+freeMemory/1024/1024);
//        if(availProcessors>0)
//        return;
        Runnable runnable=new Runnable() {
            private volatile int i=100;
            public void run() {
                while (i>0){
                    sale();
                }

            }
            synchronized private  void sale(){

                if(i>0)
                System.out.println(Thread.currentThread().getId()+": sale "+(100-(i--)+1));
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        Thread t1=new Thread(runnable);
        Thread t2=new Thread(runnable);
        t1.start();
        t2.start();
    }
}
